#include"comm.hpp"

int main()
{
    //获取key
    key_t k = ftok(PATH_NAME, PROJ_ID);
    if(k<0)
    {
        Log("creat key failed",Error)<<" client key : "<<k<<endl;
        exit(1);
    }
    Log("creat key done",Debuge)<<" client key : "<<k<<endl;

    //获取共享内存
    int shmid = shmget(k,SHM_SIZE,0);
    if(shmid<0)
    {
        Log("creat shm failed",Error)<<" client key : "<<k<<endl;
        exit(2);
    }
    Log("create shm sucess", Debuge) << " shmid : " << shmid << endl;
    sleep(10);
    //挂接共享内存
    char *shmaddr = (char *)shmat(shmid, nullptr, 0);
    if(shmaddr==nullptr)
    {
        Log("attach shm failed",Error)<<" client key : "<<k<<endl;
        exit(3);
    }
    Log("attach shm sucess", Debuge) << " shmid : " << shmid << endl;
    sleep(10);
    //使用



    //去关联
    int dt = shmdt(shmaddr);
    assert(dt != -1);
    (void)dt;
    Log("detach shm success", Debuge) << " shmid : " << shmid << endl;
    sleep(10);
    return 0;
}